<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>试题管理</title>
	<meta name="description" content="这是一个 index 页面">
	<meta name="keywords" content="index">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="renderer" content="webkit">
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="icon" type="image/png" href="../assets/i/favicon.png">
	<link rel="apple-touch-icon-precomposed" href="../assets/i/app-icon72x72@2x.png">
	<meta name="apple-mobile-web-app-title" content="Amaze UI" />
	<link rel="stylesheet" href="../assets/css/amazeui.min.css" />
	<link rel="stylesheet" href="../assets/css/amazeui.datatables.min.css" />
	<link rel="stylesheet" href="../assets/css/bootstrap.min.css">
	<link rel="stylesheet" href="../assets/css/app.css">
	<link rel="stylesheet" href="../assets/css/gb_my.css">
	<link rel="stylesheet" href="../assets/css/font-awesome.css">
	<link rel="stylesheet" href="../assets/css/bootstrap-reset.css">
	<link rel="stylesheet" href="../assets/css/easydropdown.css">
</head>
<body data-type="chart">
	<div class="am-g tpl-g">
		<!--头部-->
		<nav class="navbar navbar-default top-navbar">
			<div class="navbar-header">
				<a class="navbar-brand waves-effect waves-dark" href="javascript:;">
					<img src="../assets/img/logo.png" alt="">
					<strong>轻课网考试系统</strong>
				</a>
				<div id="sideNav" href="">
					<i class="mulv QK QK-mulu"></i>
				</div>
			</div>
			<ul class="nav navbar-top-links navbar-right aaa">
				<li>
					<a id="down_" class="sign-out dropdown-button waves-effect waves-dark" href="javascript:;">
						<span class="am-icon-sign-out"></span> 退出
					</a>
				</li>
				<li>
					<a class="dropdown-button waves-effect waves-dark" href="javascript:;"><b>欢迎你, <span class="userName"></span> </b></a>
				</li>
			</ul>
		</nav>
		<!--导航栏-->
		<nav class="navbar-default navbar-side">
			<div class="sidebar-collapse">
				<!--用户头像-->
				<div class="tpl-sidebar-user-panel">
					<div class="tpl-user-panel-slide-toggleable">
						<div class="tpl-user-panel-profile-picture">
							<img src="../assets/img/user04.png" alt="">
						</div>
					</div>
				</div>
				<dl class="list_dl">
					<dt class="list_dt">
					<a href="../index.html">
						<span class="QK1 start_before"></span>
						<p>首页</p>
					</a>
				</dt>
					<dt id="open" class="list_dt">
					<span class="QK1 topic_before"></span>
					<p>题库管理</p>
					<i class="QK1 list_dt_icon"></i>
				</dt>
					<dd class="list_dd" style="display: block">
						<ul>
							<li class="list_li">
								<a href="../questiondb/questiondb.html">管理题库</a>
							</li>
							<li class="list_li" id="style_li_a">
								<a href="../question/question.html">管理试题</a>
							</li>
						</ul>
					</dd>
					<dt class="list_dt">
					<span class="QK1 paper_before"></span>
					<p>试卷管理</p>
					<i class="QK1 list_dt_icon"></i>
				</dt>
					<dd class="list_dd">
						<ul>
							<li class="list_li">
								<a href="../paper/addpaper.html">创建试卷</a>
							</li>
							<li class="list_li">
								<a href="../paper/paper.html">管理试卷</a>
							</li>
						</ul>
					</dd>
					<dt class="list_dt">
					<span class="QK1 system_before"></span>
					<p>系统管理</p>
					<i class="QK1 list_dt_icon"></i>
				</dt>
					<dd class="list_dd">
						<ul>
							<li class="list_li">
								<a href="../system.html">系统管理</a>
							</li>
							<li class="list_li">
								<a href="../admin/admin.html">管理员</a>
							</li>
							<li class="list_li">
								<a href="../adminroles/adminroles.html">角色管理</a>
							</li>
						</ul>
					</dd>
					<dt class="list_dt">
					<span class="QK1 user_before"></span>
					<p>用户管理</p>
					<i class="QK1 list_dt_icon"></i>
				</dt>
					<dd class="list_dd">
						<ul>
							<li class="list_li">
								<a href="../user/user.html">管理用户</a>
							</li>
							<li class="list_li">
								<a href="../user/usergroup.html">用户分组</a>
							</li>
						</ul>
					</dd>
					<dt class="list_dt">
						<span class="QK1 user_before"></span>
						<p>知识点模块</p>
						<i class="QK1 list_dt_icon"></i>
					</dt>
					<dd class="list_dd">
						<ul>
							<li class="list_li">
								<a href="../KnowledgePoint/KnowledgeBlock.html">管理知识点</a>
							</li>
						</ul>
					</dd>
				</dl>
			</div>
		</nav>
		<!-- 内容区域 -->
		<div id="page-wrapper">
			<div class="row">
				<div class="col-lg-12">
					<section class="panel">
						<header class="panel-heading">
							<span class="label label-primary">试题管理</span>
							<button type="button" class="btn btn-success btn-sm add_clazz btn_my">
						<span class="QK1 QK-xinzeng"></span>&nbsp;&nbsp;新增
					</button>
						</header>
						<div class="panel-body">
							<section id="unseen">
								<div class="select_add">
									<div class="screen_all">
										<span>筛选题库</span>
										<select class="dropdown" name="question_tx" tabindex="9" data-settings='{"wrapperClass":"flat"}'>
											<option value="0">全部</option>
										</select>
									</div>
									<div class="screen_all">
										<span>筛选题型</span>
										<select class="dropdown" name="question_lx" data-value="0" tabindex="9" data-settings='{"wrapperClass":"flat"}'>
											<option value="0">全部</option>
											<option value="1">单选</option>
											<option value="2">多选</option>
											<option value="3">填空</option>
											<option value="4">判断</option>
											<option value="5">问答</option>
										</select>
									</div>
									<div class="iconic-input screen_all_span">
										<i class="QK1 QK-soushuo search"></i>
										<input type="text" class="form-control screen_all_input" placeholder="搜查一下  相关知识点">
										<ul id="ul_so"></ul>
									</div>
								</div>
								<table width="100%" class="table table-bordered table-striped table-condensed table_question table_add" id="example-r">
									<thead>
										<tr>
											<th>编号</th>
											<th>题库</th>
											<th>类型</th>
											<th>题干</th>
											<th>创建时间</th>
											<th>管理员</th>
											<th>关联状态</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody id="wraper"></tbody>
								</table>
							</section>
							<!-- 分页位置 -->
							<div>
								<ul class="box">
									<li class="prev"></li>
									<li>
										<ul class="box2"></ul>
									</li>
									<li class="next"></li>
									<li class="all_number numb"></li>
								</ul>
							</div>
						</div>
					</section>
				</div>
			</div>
		</div>
		<div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
			<div class="am-modal-dialog">
				<div class="am-modal-hd">提示</div>
				<div class="am-modal-bd">
					你，确定要删除这条记录吗？
				</div>
				<div class="am-modal-footer">
					<span class="am-modal-btn" data-am-modal-cancel>取消</span>
					<span class="am-modal-btn" data-am-modal-confirm>确定</span>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
<script src="../assets/js/jquery.min.js"></script>
<script src="../assets/js/theme.js"></script>
<script src="../assets/js/easydropdown.js"></script>
<script src="../assets/js/html5sv.js"></script>
<script type="text/javascript" src="../assets/js/jquery.cookie.js"></script>
<script src="https://img.hcharts.cn/highcharts/highcharts.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/data.js"></script>
<script src="https://img.hcharts.cn/highcharts/modules/drilldown.js"></script>
<script src="https://img.hcharts.cn/highcharts-plugins/highcharts-zh_CN.js"></script>
<script src="../assets/js/amazeui.min.js"></script>
<script src="../assets/js/amazeui.datatables.min.js"></script>
<script src="../assets/js/dataTables.responsive.min.js"></script>
<script src="../assets/js/app.js"></script>
<script>
	var change_pname = "";
	$("button").click(function() {
		window.location.href = "addquestion.html";
	});
	//删除问题
	$(document).on('click', '.tpl-table-black-operation-del', function() {
		var qid = $(this).attr("value");
//		console.log("123");
		$('#my-confirm').modal({
			relatedTarget: this,
			onConfirm: function(options){
				$.ajax({
					url: localApi + "/QuestionWithBLOBs/delete",
					type: 'POST',
					data: {
						apikey: '1',
						id: qid
					},
					success: function(result) {
						if(result.msg == "success") {
							alert("删除成功");
							window.location.href = "question.html"
						} else {
							alert("删除失败");
						}
					}

				});
			}
		});
	});
</script>
//分页
<script type="text/javascript">
	var change_sid = 0;
	var change_id = 0;
    var storage = window.sessionStorage;
    var get_page = storage['Current_page'];
    var get_select_sid = storage['select_sid'];
//    console.log(typeof(get_page));
    var get =  parseInt(get_page);//字符串转化为数字
    var get_sid =  parseInt(get_select_sid);//字符串转化为数字
	console.log(get_sid);
    if(typeof(get_page) == 'undefined'){
        getPage(1);
    }else{
        getPage(get);
    }
//    getPage(45);
	//翻页
	//	var all_data;
	$.ajax({
		url: localApi + "/QuestionDb/all",
		type: 'get',
		async: false,
		data: {
			apikey: '1'
		},
		success: function(result) {
			//            console.log(result.data);
			$.each(result.data, function(n, item) {
				$("select[name='question_tx']").append("<option value='" + item.id + "'>" + item.dname + "</option>");
//				                console.log(item.id);
			});
			//            all_data = result.data;
		}
	});
//    var select_sid_html;
//    if(typeof(get_select_sid) == 'undefined'){
//        $("select[name='question_tx']").attr('data-value' , 0);
//    }else{
//        $("select[name='question_tx']").attr('data-value' , get_sid);
//        $.each($("select[name='question_tx']").children() , function (n , item) {
//            if($(this).attr('value') == get_sid){
//                select_sid_html = $(this).html();
//            }
//        })
//    }
//    console.log(select_sid_html);
//    $('.selected').html(select_sid_html);
	//保存定时器ID
	var tid = null;

	//延迟执行函数
	function debounce(fn, wait) {
		//设定默认的延迟时间
		wait = wait || 500;
		//清除定时器
		tid && clearTimeout(tid);
		//定时器执行
		tid = setTimeout(fn, wait);
	}
	var index = -1;
	$('.screen_all_input').keyup(function(e) {
		//获取关键词
		var keyword = $(this).val();
		var arry_name = [];
		var ul_add;
		var $as;
		//AJAX请求
		debounce(function() {
			//            $.get('server/search.php',{keyword:keyword},function(res){
			//                console.log(res);
			//            })
			$.ajax({
				url: localApi + "/QuestionDbPoint/getByName",
				type: 'get',
				async: false,
				data: {
					apikey: '1',
					pname: keyword
				},
				success: function(result) {
					//                    console.log(result.data);
					$.each(result.data, function(n, item) {
						//						console.log(item);
						arry_name.push(item.pname);
					});
					$("#ul_so").empty();
					//                    console.log(arry_name);
					for(var a = 0; a < arry_name.length && a <= 10; a++) {
						ul_add = '<li class="ul_lis">' + arry_name[a] + '</li>';
						//console.log(ul_add);
						$("#ul_so").append(ul_add);
						$("#ul_so").show();
						//console.log($(".screen_all_input").width());
						$("#ul_so").width();
					}
				}
			});
			//隐藏列表框
			$("body").click(function() {
				$(".ul_lis").css('display', 'none');
			});
			$(document).on('click', '.ul_lis', function() {
				//                console.log($(this).text());
				$(".screen_all_input").val($(this).text());
				index = -1;
			});
			$as = $(".ul_lis");
			//            console.log($as);
			var keycode = e.keyCode;
			if(keycode === 38) {
				console.log(index);
				if(index === -1) {
					index = $as.length - 1;
					$($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
				} else if(index === -1 || index === 0) {
					index = $as.length - 1;
					$($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
				} else {
					index--;
					$($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
				}
			} else if(keycode === 40) {
//				console.log(index);
				if(index === ($as.length - 1)) {
					index = 0;
					$($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
				} else {
					index++;
					$($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
				}
			} else if(keycode === 13) {
				$('.screen_all_input').val($($as[index]).text());
				$("#ul_so").hide();
                change_pname = $(".screen_all_input").val();
				getPage(1);
//				index = -1;
			} else {
				$($as[index]).addClass('hover_add').siblings().removeClass('hover_add');
			}
			$(".ul_lis").mouseover(function() {
				$(this).addClass('hover_add').siblings().removeClass('hover_add');
			}).mouseout(function() {
				$(this).addClass('hover_add').siblings().removeClass('hover_add');
			});
		}, 200);
	});
	
	$(document).on('click', '.search', function() {
//		console.log(111);
		change_pname = $(".screen_all_input").val();
		getPage(1);
		//		console.log(change_pname);
	});
	//弹出列表框
	$(".screen_all_input").click(function() {
		$(".ul_lis").css('display', 'block');
		return false;
	});
	$(document).ready(function() {
		$("select[name='question_tx']").change(function() {
			change_sid = $(this).children("option:selected").val();
			console.log(change_sid);
            storage['select_sid'] = change_sid;
            getPage(1);
		});
		$("select[name='question_lx']").change(function() {
			change_id = $(this).children("option:selected").val();
//			console.log(change_id);
			getPage(1);
		});
	});
	function getPage(pn) {
        $.ajax({
            url: localApi + "/QuestionWithBLOBs/count",
            type: 'get',
            contentType: 'application/x-www-form-urlencoded; charset=utf-8',
            data: {
                apikey: '1',
                dbid: change_sid,
                qtype: change_id,
                pname: change_pname
            },
            success: function(result) {
                count = result.data;
//                page = Math.round(count / 10);
                var dataCount = count; //总数据条数
                var pageSize = 10; //每页显示条数
                var pageCount = Math.ceil(dataCount / pageSize); //总页数
//            if(pn == 0 || pn > pageCount) {
//                return;
//            }
                var ul = $("#wraper");
                ul.empty();
            	paintPage(pageCount, pn); //绘制页码
                $.ajax({
                    url: localApi + "/QuestionWithBLOBs/index",
                    type: 'get',
                    data: {
                        apikey: '1',
                        limit: '10',
                        offset: ((pn - 1) * 10),
                        dbid: change_sid,
                        qtype: change_id,
                        pname: change_pname
                    },
                    success: function(result) {
                        var ids = [];
                        $.each(result.data, function(n, item) {
                            if(item.questionDb != null) {
                                var dname = item.questionDb.dname
                            } else {
                                dname = "null"
                            }
                            if(item.qtype == 1) {
                                var qtype = "单选"
                            } else if(item.qtype == 2) {
                                qtype = "多选"
                            } else if(item.qtype == 3) {
                                qtype = "填空"
                            } else if(item.qtype == 4) {
                                qtype = "判断"
                            } else {
                                qtype = "问答"
                            }
                            if(item.status == 1) {
                                var status = "开放"
                            } else {
                                status = "锁定"
                            }
							if(typeof(item.questionDbPoint) == 'undefined'){
								var point = "未关联"
							}else{
							point = "关联"
							}
                            var content = item.content;
                            var content_s = content.replace(/<[^>]+>/g, ""); //去除html标签
                            var content_ss = content_s.replace('&nbsp;', "");
                            var coulmn = '<tr class="even gradeX student add_p2"><td>' + item.id + '</td><td>' + dname + '</td><td>' + qtype + '</td><td>' + content_ss + '</td><td>' + formatDate(item.postdate) + '</td><td class=adminid' + item.adminid + '></td><td>' + point +'</td>';
                            coulmn += '<td class="operation">' +
								'<div class="tpl-table-black-operation">' +
								'<a href="updatequestion.html?id=' + item.id + '" class="edit_student button button--aylen">' +
								'<i class="QK1 QK-bianji"></i> 编辑</a>' +
                                '<a href="javascript:;" value=' + item.id + ' class="tpl-table-black-operation-del button button--aylen" >' +
								'<i class="QK1 QK-shanchu spacing_detail"></i>删除</a>' +
								'</div></td></tr>';
                            $("table tbody").append(coulmn);
                            ids[n] = item.adminid;
                        });
                        $('.add_p2').children('td:nth-child(4)').children('p:first-child').siblings().empty();
                        $.ajax({
                            type: "post",
                            url: localApi2 + "/user/selectByIdArray",
                            data: {
                                para: ids
                            },
                            success: function(result) {
                                $.each(result.data.record, function(n,item) {
                                    $(".adminid"+item.id).text(item.userName);
                                });

                            }
                        });

                    }
                });

            }
        });
	}
	//绘制页码
	function paintPage(number, currNum) //number 总页数,currNum 当前页
	{
		var pageUl = $(".box");
		var nextLi = $('.next'),
			prevLi = $('.prev'),
			pageUl2 = $('.box2'),
			pageNumber = $('.all_number');
        nextLi.empty();
        prevLi.empty();
        pageUl2.empty();
        pageNumber.empty();
		var ulDetail = "";

		//上一页
        if(currNum > 1){
            prevLi.append('<a href="javascript:getPage(' + parseInt(currNum - 1) + ')" class="prevPage"><上一页</a>');
        }else{
            prevLi.remove('.prevPage');
            prevLi.append('<span class="disabled"><上一页</span>');
        }
        //中间页码
        if(currNum != 1 && number >= 4 && number != 4 && currNum >= 4){
            pageUl2.append('<li class="numb"><a href="javascript:getPage(1)" class="tcdNumber">'+1+'</a></li>');
        }
        if(currNum-2 > 2 && currNum <= number && number > 5){
            pageUl2.append('<li class="li_span"><span>...</span></li>');
        }
        var start = currNum -2,end = currNum+2;
        if((start > 1 && currNum < 4)||currNum == 1){
            end++;
        }
        if(currNum > number-4 && currNum >= number){
            start--;
        }
        for (;start <= end; start++) {
            if(start <= number && start >= 1){
                if(start != currNum){
                    pageUl2.append('<li class="numb"><a href="javascript:getPage('+ start +')" class="tcdNumber">'+ start +'</a></li>');
                }else{
                    pageUl2.append('<li class="numb choose"><span class="current">'+ start +'</span></li>');
                }
            }
        }
        if(currNum + 2 < number - 1 && currNum >= 1 && number > 5){
            pageUl2.append('<li class="li_span"><span>...</span></li>');
        }
        if(currNum != number && currNum < number -2  && number != 4){
            pageUl2.append('<li class="numb"><a href="javascript:getPage('+ number +')" class="tcdNumber">'+number+'</a></li>');
        }
        //下一页
        if(currNum <number){
            nextLi.append('<a href="javascript:getPage(' + parseInt(currNum + 1) + ')" class="nextPage">下一页></a>');
        }else{
            nextLi.remove('.nextPage');
            nextLi.append('<span class="disabled">下一页></span>');
        }
        pageNumber.append('<span class="pagecount">共'+number+'页</span>');
		if(currNum == 1) {
			$('.prev').removeClass('selected_paging').removeClass('hover').css('cursor', 'text').find('a').css('cursor', 'text');
		}
		if(currNum == 1 && number > 1) {
			$('.next').addClass('selected_paging');
		}
		if(currNum == number) {
			$('.next').removeClass('selected_paging').removeClass('hover').css('cursor', 'text').find('a').css('cursor', 'text');
		}
		if(currNum == number && currNum > 1) {
			$('.prev').addClass('selected_paging');
		}
		if(currNum !== number && currNum > 1) {
			$('.prev').addClass('selected_paging');
			$('.next').addClass('selected_paging');
		}
        storage['Current_page'] = currNum;
        $('.choose').addClass('selected_paging').siblings().removeClass('selected_paging').addClass('hover');
	}
</script>
<script>
	$(document).ready(function() {
		$(".list_dt").on("click", function() {
			$('.list_dd').stop();
			$(this).siblings("dt").removeAttr("id");
			if($(this).attr("id") == "open") {
				$(this).removeAttr("id").siblings("dd").slideUp();
			} else {
				$(this).attr("id", "open").next().slideDown().siblings("dd").slideUp();
			}
		});
	});
</script>
<script>
	$(document).ready(function() {
		$(".dropdown-button").dropdown();
		$("#sideNav").click(function() {
			if($(this).hasClass('closed')) {
				$('.navbar-side').animate({
					left: '0px'
				});
				$(this).removeClass('closed');
				$('#page-wrapper').animate({
					'margin-left': '260px'
				});
			} else {
				$(this).addClass('closed');
				$('.navbar-side').animate({
					left: '-260px'
				});
				$('#page-wrapper').animate({
					'margin-left': '0px'
				});
			}
		});
	});
	$(".dropdown-button").dropdown();
</script>